/*
 * Created on 02.05.2006
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package ro.qi.framework.sys.users.profile.entities;

/**
 * @author Luiza Varovici
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */

import java.util.Hashtable;
import java.util.Vector;

import ro.qi.framework.sys.entities.Entity;

public class UsersAccountProfileQuestion extends Entity {

	public static final int TYPE_RADIO			= 1;
	public static final int TYPE_COMBO			= 2;
	public static final int TYPE_CHECK			= 3;
	public static final int TYPE_EDIT			= 4;
	public static final int TYPE_DATE			= 5;
	public static final int TYPE_TEXTAREA		= 6;
	public static final int TYPE_GROUP_RADIO	= 7;
	public static final int TYPE_GROUP_CHECK	= 8;
	public static final int TYPE_ITEM			= 9;
	public static final int TYPE_LABEL			= 10;

	public UsersAccountProfileQuestion() {
		super();
	}

	public UsersAccountProfileQuestion(Integer id) {
		super();
		setValue("id", id);
		select();
	}

	public UsersAccountProfileQuestion(int id) {
		super();
		setValue("id", new Integer(id));
		select();
	}

	public int getId() {
		return ((Integer)getValue("id")).intValue();
	}

	public void setGroupId(int value) {
		setValue("groupId", new Integer(value));
	}

	public int getGroupId() {
		return ((Integer)getValue("groupId")).intValue();
	}

	public void setType(int value) {
		setValue("type", new Integer(value));
	}

	public int getType() {
		return ((Integer)getValue("type")).intValue();
	}
	
	public String getTypeText() {		
		switch(getType())
		{
			case TYPE_RADIO : 
				return "TYPE_RADIO";
			case TYPE_COMBO : 
				return "TYPE_COMBO";
			case TYPE_CHECK : 
				return "TYPE_CHECK";
			case TYPE_EDIT : 
				return "TYPE_EDIT";
			case TYPE_DATE : 
				return "TYPE_DATE";
			case TYPE_TEXTAREA : 
				return "TYPE_TEXT";	
			case TYPE_GROUP_RADIO : 
				return "TYPE_GROUP_RADIO";
			case TYPE_GROUP_CHECK : 
				return "TYPE_GROUP_CHECK";
			case TYPE_ITEM : 
				return "TYPE_ITEM";	
			case TYPE_LABEL : 
				return "TYPE_LABEL";			
			default:
				return "";	
		}			
	}

	public void setText(String value) {
		setValue("text", value);
	}

	public String getText() {
		return (String)getValue("text");
	}

	public void setRequired(boolean value) {
		setValue("required", new Integer((value)?1:0));
	}

	public boolean isRequired() {
		return ((Integer)getValue("required")).intValue() == 1;
	}


	public void setPrevId(int value) {
		setValue("prevId", new Integer(value));
	}

	public int getPrevId() {
		return ((Integer)getValue("prevId")).intValue();
	}

	public void setNextId(int value) {
		setValue("nextId", new Integer(value));
	}

	public int getNextId() {
		return ((Integer)getValue("nextId")).intValue();
	}

	public void setPublished(boolean value) {
		setValue("published", new Integer((value)?1:0));
	}

	public boolean isPublished() {
		return ((Integer)getValue("published")).intValue() == 1;
	}

	public int getNoAnswers() {
		return ((Vector)getValue("answers")).size();
	}
	
	public int getAnswerId(int index) {
		if( index < getNoAnswers() ) {
			Hashtable tmp = (Hashtable)(((Vector)getValue("answers")).get(index));
			if( tmp.containsKey("answerId") )
				return Integer.parseInt(tmp.get("answerId").toString());
		}
		return 0;
	}
	
	public UsersAccountProfileAnswer getAnswer(int index) {
		int answerId = getAnswerId(index);
		if (answerId > 0)
			return new UsersAccountProfileAnswer(answerId);
		return null;
	}
	
	public UsersAccountProfileQuestion getNextQuestion() {
		if (getNextId() > 0)
			return new UsersAccountProfileQuestion(getNextId());
		return null;
	}

	public int getNoResponses() {
		return ((Vector)getValue("responses")).size();
	}
	
	public int getResponseId(int index) {
		if( index < getNoResponses() ) {
			Hashtable tmp = (Hashtable)(((Vector)getValue("responses")).get(index));
			if( tmp.containsKey("responseId") )
				return Integer.parseInt(tmp.get("responseId").toString());
		}
		return 0;
	}
	
	public UsersAccountProfileResponse getResponse(int index) {
		int responseId = getResponseId(index);
		if( responseId > 0 )
			return new UsersAccountProfileResponse(responseId);
		return null;
	}

	public int getNoItems() {
		return ((Vector)getValue("items")).size();
	}
	
	public int getItemId(int index) {
		if( index < getNoItems() ) {
			Hashtable tmp = (Hashtable)(((Vector)getValue("items")).get(index));
			if( tmp.containsKey("itemId") )
				return Integer.parseInt(tmp.get("itemId").toString());
		}
		return 0;
	}

	public UsersAccountProfileQuestion getItem(int index) {
		int itemId = getItemId(index);
		if( itemId > 0 )
			return new UsersAccountProfileQuestion(itemId);
		return null;
	}

	public UsersAccountProfileAnswer getFirstAnswer() {
		if( getNoAnswers() > 0 ) {
			UsersAccountProfileAnswer answer = getAnswer(0);
			while( answer.getPrevId() > 0 )
			answer = new UsersAccountProfileAnswer(answer.getPrevId());
			return answer;
		}
		return null;
	}

	public UsersAccountProfileAnswer getLastAnswer() {
		if( getNoAnswers() > 0 ) {
			UsersAccountProfileAnswer answer = getAnswer(0);
			while( answer.getNextId() > 0 )
				answer = new UsersAccountProfileAnswer(answer.getNextId());
			return answer;
		}
		return null;
	}

	public UsersAccountProfileQuestion getFirstItem() {
		if( getNoItems() > 0 ) {
			UsersAccountProfileQuestion item = getItem(0);
			while( item.getPrevId() > 0 )
				item = new UsersAccountProfileQuestion(item.getPrevId());
			return item;
		}
		return null;
	}

	public UsersAccountProfileQuestion getLastItem() {
		if( getNoItems() > 0 ) {
			UsersAccountProfileQuestion item = getItem(0);
			while( item.getNextId() > 0 )
				item = new UsersAccountProfileQuestion(item.getNextId());
			return item;
		}
		return null;
	}

}

